package com.jinyu.admin.service.sys.impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import cn.hutool.core.util.IdUtil;
import com.jinyu.dao.entity.sys.SysUser;
import com.jinyu.admin.service.sys.SysUserService;
import com.jinyu.dao.mapper.sys.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: yangli
 * @Despriction:
 * @Package: com.jinyu.admin.service.sys.impl
 * @Date:Created in 2022/5/3 22:13
 * @Modify By:
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public int insert(SysUser sysUser) {
        long snowflakeNextId = IdUtil.getSnowflakeNextId();
        sysUser.setId(snowflakeNextId);
        //密码进行md5加密
        String md5Password = SaSecureUtil.md5(sysUser.getPassWord());
        sysUser.setPassWord(md5Password);
        return sysUserMapper.insert(sysUser);
    }

    @Override
    public int delete(String id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser selectByOne(String userName) {
        return sysUserMapper.selectByOne(userName);
    }

    @Override
    public List<SysUser> pageList(int offset, int pagesize) {
        return sysUserMapper.pageList(offset,pagesize);
    }
}
